﻿
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using TShockAPI;

namespace BeanPoints
{
    public static class ConfigUtils {
        public static BConfig config=new BConfig();
        public static Dictionary<int, int> monsterValue = new Dictionary<int, int>(); 
        public readonly static string DicPath = TShock.SavePath + "/BeanPoints";
        public readonly static string configPath = DicPath + "/config.json";
        public readonly static string monstersetPath = DicPath + "/mobvalues.json";
        public static void ReadConfig() {
            if (!Directory.Exists(DicPath))
            {
                Directory.CreateDirectory(DicPath);
                File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
                File.WriteAllText(monstersetPath, JsonConvert.SerializeObject(monsterValue, Formatting.Indented));
            }
            else {
                if (!File.Exists(configPath))
                {
                    File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
                }
                else {
                    config = JsonConvert.DeserializeObject<BConfig>(File.ReadAllText(configPath));
                }
                if (!File.Exists(monstersetPath))
                {
                    File.WriteAllText(monstersetPath, JsonConvert.SerializeObject(monsterValue, Formatting.Indented));
                }
                else
                {
                    monsterValue = JsonConvert.DeserializeObject<Dictionary<int,int>>(File.ReadAllText(monstersetPath));
                }
            }
        
        }
        public static void WriteMobValue()
        {
            File.WriteAllText(monstersetPath, JsonConvert.SerializeObject(monsterValue, Formatting.Indented));
        }
        public static void WriteConfig()
        {
            File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
        }
    }
    public class BConfig
    {
        public string CurrencyName { get; set; }
        public int DropRate { get; set; }
        public bool AutoMobValue { get; set; }
        public bool EnableMonstersDrop { get; set; }
        public bool AllowCoinsExchange { get; set; }
        public bool DisableChangeBoard { get; set; }
        public bool ShowAboveHead { get; set; }
        public Dictionary<string, int> CoinValue { get; set; }
        public BConfig() {
            CurrencyName = "游戏币";
            DropRate = 2;
            AutoMobValue = true;
            EnableMonstersDrop = false;
            AllowCoinsExchange = true;
            CoinValue = new Dictionary<string, int>();
            CoinValue.Add("Copper",100);
            CoinValue.Add("Silver",200);
            CoinValue.Add("Gold",300);
            CoinValue.Add("Platinum", 400);
        }
    }
}
